package com.winhxd.b2c.product.api;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramAddCondition;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramAddDetailCondition;
import com.winhxd.b2c.common.domain.product.condition.ProductPriceProgramCondition;
import com.winhxd.b2c.common.domain.product.model.ProductPriceProgram;
import com.winhxd.b2c.common.domain.product.vo.ProductPriceProgramWithSpuVO;
import com.winhxd.b2c.product.service.ProductPriceProgramService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 商品价格方案外部接口
 * @Author cuipengbo
 */

@Api(value = "价格方案", tags = "Api priceProgram")
@RestController
@RequestMapping(value = "/api-product", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class ApiProductPriceProgramController{

    @Autowired
    private ProductPriceProgramService productPriceProgramService;

    @ApiOperation(value = "查询价格方案详情")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @RequestMapping(value = "/priceProgram/8801/v1/findProductPriceProgramDetail", method = RequestMethod.POST)
    public ResponseResult<ProductPriceProgramWithSpuVO> findProductPriceProgramDetail(@RequestBody ProductPriceProgramAddDetailCondition condition) {
        ResponseResult<ProductPriceProgramWithSpuVO> result = new ResponseResult<>();
        result.setData(productPriceProgramService.findProductPriceProgramDetail(condition));
        return result;
    }

    @ApiOperation(value = "删除价格方案")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @RequestMapping(value = "/priceProgram/8803/v1/deleteProductPriceProgram", method = RequestMethod.POST)
    public ResponseResult<Integer> deleteProductPriceProgram(@RequestBody ProductPriceProgramCondition condition) {
        ResponseResult<Integer> result = new ResponseResult<>();
        result.setData(productPriceProgramService.deleteProductPriceProgram(condition.getId()));
        return result;
    }

    @ApiOperation(value = "根据条件查询价格方案")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @RequestMapping(value = "/priceProgram/8805/v1/findProductPriceProgramByModel", method = RequestMethod.POST)
    public ResponseResult<List<ProductPriceProgram>> findProductPriceProgramByModel(@RequestBody ProductPriceProgramCondition condition) {
        ResponseResult<List<ProductPriceProgram>> result = new ResponseResult<>();
        result.setData(productPriceProgramService.findProductPriceProgramByModel(condition));
        return result;
    }

    @ApiOperation(value = "新增价格方案")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @RequestMapping(value = "/priceProgram/8807/v1/addProductPriceProgram", method = RequestMethod.POST)
    public ResponseResult<Boolean> addProductPriceProgram(@RequestBody ProductPriceProgramAddCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        productPriceProgramService.addProductPriceProgram(condition);
        result.setData(true);
        result.setCode(BusinessCode.CODE_OK);
        return result;
    }

    @ApiOperation(value = "修改价格方案")
    @ApiResponses({ @ApiResponse(code = BusinessCode.CODE_OK, message = "成功"),
            @ApiResponse(code = BusinessCode.CODE_1001, message = "服务器内部异常"),
            @ApiResponse(code = BusinessCode.CODE_1007, message = "参数无效")})
    @RequestMapping(value = "/priceProgram/8809/v1/modifyProductPriceProgram", method = RequestMethod.POST)
    public ResponseResult<Boolean> modifyProductPriceProgram(@RequestBody ProductPriceProgramAddCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        productPriceProgramService.modifyProductPriceProgram(condition);
        result.setData(true);
        result.setCode(BusinessCode.CODE_OK);
        return result;
    }
}
